import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class SqlGenerator {
	public static void main(String[] args) {
		
		
		
//		String[] values = {};
//		System.out.println("delete from `customerextra` where customerid="+values[0]+" and attribute='SalesRegion';");
//		System.out.println("INSERT INTO `customerextra` (`customerid`, `attribute`, `value`, `description`) VALUES ("+values[0]+", 'SalesRegion', '"+values[1]+"', '"+values[2]+"');");
		
		
		List result =readFileByLines("D:\\dd.txt");
		for (Iterator iterator = result.iterator(); iterator.hasNext();) {
			String[] values = (String[]) iterator.next();
			
			System.out.println("delete from `customerextra` where customerid="+values[0]+" and attribute='SalesRegion';");
			System.out.println("INSERT INTO `customerextra` (`customerid`, `attribute`, `value`, `description`) VALUES ("+values[0]+", 'SalesRegion', '"+values[2]+"', '"+values[3]+"');");
			
		}

	}
	
	
    public static List readFileByLines(String fileName) {
        File file = new File(fileName);
        List result = new ArrayList();
        BufferedReader reader = null;
        try {
            System.out.println("以行为单位读取文件内容，一次读一整行：");
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int line = 1;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
                System.out.println("line " + line + ": " + tempString);
                String[] values = tempString.split("\t");
                result.add(values);
                line++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        return result;
    }
}